package cn.kgc.maoqichao.microservicecloudproviderdept8001.controller;

import cn.kgc.maoqichao.microservicecloudproviderdept8001.pojo.Category;
import cn.kgc.maoqichao.microservicecloudproviderdept8001.pojo.ResultEntity;
import cn.kgc.maoqichao.microservicecloudproviderdept8001.pojo.Workorder;
import cn.kgc.maoqichao.microservicecloudproviderdept8001.service.WorkorderService;
import com.github.pagehelper.PageInfo;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/provider/category")
public class WorkorderController {
    @Resource
    WorkorderService workorderService;
    @RequestMapping("/search/by/keyword")
    public ResultEntity<PageInfo<Workorder>> search(
            @RequestParam(value="pageNum", defaultValue="1",required = false) Integer pageNum,
            @RequestParam(value="pageSize", defaultValue="5",required = false) Integer pageSize,
            @RequestParam(value="keyword", defaultValue="",required = false) String keyword
    ){
        // 1.查询得到PageInfo对象
        PageInfo<Workorder> pageInfo = workorderService.queryWorkAll(pageNum, pageSize, keyword);
        // 2.封装结果对象返回
        return ResultEntity.successWithoutData(pageInfo);
    }

    @ResponseBody
    @RequestMapping("/get/list/by/id/list")
    public ResultEntity<List<Workorder>> getRoleListByIdList(@RequestBody List<Integer> workIdList) {
        List<Workorder> workList = workorderService.getAll(workIdList);
        return ResultEntity.successWithoutData(workList);
    }

    @RequestMapping("/save/work")
    @ResponseBody
    public ResultEntity<String> saveBlog(Workorder workorder) {
        workorderService.saveWork(workorder);
        return ResultEntity.successWithoutData();
    }
    @ResponseBody
    @RequestMapping("/delete/work")
    public ResultEntity<String> batchRemove(@RequestBody List<Integer> workIdList) {
        workorderService.deleteWork(workIdList);
        return ResultEntity.successWithoutData();
    }
    @ResponseBody
    @RequestMapping("/update/work")
    public ResultEntity<String> updateRole(Workorder workorder) {
        workorderService.updateWork(workorder);
        return ResultEntity.successWithoutData();
    }
}
